package com.edunera;

import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.edunera.connection.TaskGetCourses;
import com.edunera.connection.TaskIsConnectedBefore;
import com.edunera.models.edu_courses;

import java.util.ArrayList;
import java.util.List;

public class ActivityMain extends ListActivity {
    /**
     * Called when the activity is first created.
     */
    final Context context=this;
    List<edu_courses> list;
    private String user_device_id;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        user_device_id= Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);



        new TaskGetCourses(context, user_device_id) {
            @Override
            public void onComplete() {
                if(edu_coursesList.size()>0){
                    list=edu_coursesList;
                    setListAdapter(new ArrayAdapter<edu_courses>(
                            context,
                            R.layout.list_item_course,
                            R.id.textView,
                            edu_coursesList));
                }else{
                    list=new ArrayList<edu_courses>();
                }
            }
        }.execute();



    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {

        startActivity(new Intent(this, ActivityDetail.class)
                .putExtra("itemId", list.get(position).course_id)
        );
    }


}
